package com.my.api.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.coolq.strategy.ReceiveMessagesHandleStrategy;
import com.my.coolq.strategy.ReceiveMessagesHandleStrategySupport;

/**
 * 接收消息控制器
 * @author ch
 *
 */
@Controller
public class ReceiveMessageController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ReceiveMessageController.class);
	
	@Autowired
	private ReceiveMessagesHandleStrategySupport receiveMessagesHandleStrategySupport;
	
	@RequestMapping(value = "receive_message", produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Object receiveMessages(@RequestBody Map<String, Object> params){
		LOGGER.info("messages={}",params);
		ReceiveMessagesHandleStrategy receiveMessagesHandleStrategy = receiveMessagesHandleStrategySupport.getReceiveMessagesHandleStrategy(String.valueOf(params.get("post_type")));
		return receiveMessagesHandleStrategy==null?null:receiveMessagesHandleStrategy.handle(params);
	}
}
